using UnityEngine;

//通过点乘判断目标方位
public class Lesson2 : MonoBehaviour
{
    public Transform player;
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        Debug.DrawRay(transform.position, player.position - transform.position, Color.red);
        Debug.LogFormat("magnitude:{0}", (player.position - transform.position).magnitude);
        //得到两个向量的点乘结果
        float dotResult = Vector3.Dot(transform.forward, player.position - transform.position);
        if (dotResult >= 0)
            Debug.LogFormat("目标在我前方 dot:{0}", dotResult);
        else
            Debug.LogFormat("目标在我后方 dot:{0}", dotResult);

        dotResult = Vector3.Dot(transform.right, player.position - transform.position);
        if (dotResult >= 0)
            Debug.LogFormat("目标在我右侧 dot:{0}", dotResult);
        else
            Debug.LogFormat("目标在我左侧 dot:{0}", dotResult);

        dotResult = Vector3.Dot(transform.up, player.position - transform.position);
        if (dotResult >= 0)
            Debug.LogFormat("目标在我上方 dot:{0}", dotResult);
        else
            Debug.LogFormat("目标在我下方 dot:{0}", dotResult);
    }
}
